package my.edu.model.commodity.entity.dto;

import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import jakarta.validation.groups.Default;
import lombok.Data;
import my.edu.common.validate.groups.Insert;
import my.edu.common.validate.IntegerPattern;

import java.math.BigDecimal;
import java.util.List;

@Data
public class PricingSchemeDTO {
    //NotEmpty：对于字符串：不为null且不为空字符串，对应集合，数组：不为null且不为空，不可校验数值
    //NotBlank：只加在字符串，不为null且不为空字符串，也不为空白字符：空格、制表符（\t）、换行符（\n）、回车符（\r）等不可见字符
    //NotNull：字段不为null
    @Null(message = "id必须为空", groups = Insert.class)
    @NotNull(message = "id不能为空" ,groups = { Default.class})
    private Long id;
    @NotBlank(message = "编号不能为空", groups = {Insert.class, Default.class})
    private String schemeNo;
    @NotBlank(message = "名称不能为空", groups = {Insert.class, Default.class})
    private String schemeName;
    private String remark;
    @IntegerPattern(regexp = "^[01]$", message = "状态参数错误", groups = {Insert.class, Default.class})
    private Integer status;
    @Valid
    @NotEmpty(message = "方案详情不能为空", groups = {Insert.class, Default.class})
    private List<PricingSchemeDetailDTO> detailList;

    @Data
    static public class PricingSchemeDetailDTO {
        @NotNull(message = "价格字段编号不能为空", groups = {Insert.class, Default.class})
        private Long priceFieldId;
        @NotBlank(message = "价格字段规则不能为空", groups = {Insert.class, Default.class})
        @Pattern(regexp = "^[+\\-*/]$", message = "价格字段规则参数错误", groups = {Insert.class, Default.class})
        private String operator;
        @NotNull(message = "价格不能为空", groups = {Insert.class, Default.class})
        private BigDecimal value;
    }
}
